<?php
include('include/config.inc.php');
if(!isset($_SESSION['s_activId'.$cfgPack])
  || (isset($_SESSION['s_userType'.$cfgPack]) && isset($cfgFileNames['complainservice'][$_SESSION['s_userType'.$cfgPack]]) 
      && $cfgFileNames['complainservice'][$_SESSION['s_userType'.$cfgPack]] == 0))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{	
	/////////////////  Filter date View:Start
	if(isset($_REQUEST['fromDateYear']))
		$fromDate  = $_REQUEST['fromDateYear']."-".$_REQUEST['fromDateMonth']."-".$_REQUEST['fromDateDay'];
	else
		$fromDate  = "2011-00-00";
	
	if(isset($_REQUEST['toDateYear']))
		$toDate    = $_REQUEST['toDateYear']."-".$_REQUEST['toDateMonth']."-".$_REQUEST['toDateDay'];
	else
		$toDate    = date("Y-m-32");
	/////////////////  Filter date View:Stop
 
  
  //query for R and R List : Starts //
  $differenciat = "";
  $count = 0;
  $productArray = array();
  
  $selectProduct = "SELECT party.companyName,randrmaster.srNo,supplier.companyName AS supplier,randrmaster.address,
                           DATE_FORMAT(randrmaster.complaintDate,'%d-%m-%Y') AS complaintDate,
                           DATE_FORMAT(randrmaster.targetDate,'%d-%m-%Y') AS targetDate,
                           DATE_FORMAT(randrmaster.closeDate,'%d-%m-%Y') AS closeDate,
                           randrmaster.rAndRMasterId
                      FROM randrmaster
                      JOIN party ON party.partyId = randrmaster.partyId
                      JOIN supplier ON supplier.supplierId = randrmaster.supplierId
                     WHERE randrmaster.status = 'D'
                       AND complaintDate >= '".$fromDate."'
                       AND complaintDate <= '".$toDate."' ";                    
  $selectProductRes = mysql_query($selectProduct);
  while($row = mysql_fetch_array($selectProductRes))
  {
  	$productArray[$count]['rAndRMasterId'] = $row['rAndRMasterId'];
  	$productArray[$count]['companyName']   = $row['companyName'];
  	$productArray[$count]['srNo']          = $row['srNo'];
  	$productArray[$count]['supplier']      = $row['supplier'];
  	$productArray[$count]['address']       = $row['address'];
  	$productArray[$count]['complaintDate'] = $row['complaintDate'];
  	$productArray[$count]['targetDate']    = $row['targetDate'];
  	$productArray[$count]['closeDate']     = $row['closeDate'];
  	//pending days count :Start
  	$pendingDays                           = strtotime($row['targetDate']);
  	$currentdate                           = strtotime(date("d-m-Y"));
  	$finalDays                             = abs($pendingDays - $currentdate);
  	$numberDays                            = $finalDays/86400;
  	$productArray[$count][$differenciat]   = intval($numberDays);
  	//pending days count :End
  	$count++;
  }
  //query for R and R List : Ends //

  include("./bottom.php");
  $smarty->assign("msg",$msg);
  $smarty->assign("serviceTotal",$serviceTotal);
  $smarty->assign("fromDate",$fromDate);
  $smarty->assign("toDate",$toDate);
  $smarty->assign("amountTotal",$amountTotal);
  $smarty->assign("complainCallDetailArray",$complainCallDetailArray);
  $smarty->assign("productArray",$productArray);
  if($print == 1)
    $smarty->display("rNrPrint.tpl");
  else
  $smarty->display("completeRandRList.tpl");
}
?>